package net.searchdata.study;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.junit.Test;

public class Entry28Two {
	public <E> Set<E> union(Set<? extends E> set1, Set<? extends E> set2) {
		Set<E> set = new HashSet<E>(set1);
		set.addAll(set2);

		return set;
	}

	@Test
	public void testUnion() {
		Set<Integer> set1 = new HashSet<Integer>();
		Set<Double> set2 = new HashSet<Double>();

		set1.addAll(Arrays.asList(1, 2, 3));
		set2.addAll(Arrays.asList(4.0, 5.0, 6.0));

		Set<Number> set = this.<Number>union(set1, set2);
		assertThat(set.size(), is(6));
	}
}
